package servlet.miniprojet.test;


import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

import servlet.miniprojet.bdd.ConnectionBDD;
import servlet.miniprojet.modele.Utilisateur;


public class Main {

	
	public static void main(String[] args) {
		
		Connection conn=null;
		ConnectionBDD connBDD= null;
		ResultSet affichage=null;
		String value = null;
		try {
				
			conn = ConnectionBDD.getInstance();		

			Statement state=null;
			ResultSet resultat = null;
			String valUtilisateur =null;
			
			state = conn.createStatement();
			resultat = state.executeQuery("SELECT username FROM User WHERE username='truc';");
			//resultat.next();
			System.out.println(resultat.next());
			valUtilisateur = resultat.getObject(1).toString();
			System.out.println(valUtilisateur + "valutilisateur");

			//resultat.next();
			//System.out.println(resultat.getObject(1));
			
			//affichage = connBDD.query("SELECT idUser, username FROM User WHERE username='truc' and password='bidule';");
			//connBDD.update("INSERT INTO User (username, password) VALUES('autretruc','autrebidule')");	
			ResultSetMetaData resultMeta = resultat.getMetaData();

			
			//System.out.println("\n**********************************");
			//On affiche le nom des colonnes
			//for(int i = 1; i <=  resultMeta.getColumnCount(); i++)
			//	System.out.print("\t" + resultMeta.getColumnName(i).toUpperCase() + "\t *");
			
			//System.out.println("\n**********************************");
			//System.out.println(resultat.getObject(1));
			while(resultat.next()){
		
				for(int i = 1; i <=  resultMeta.getColumnCount(); i++){
					//if(resultat.getObject(1).toString()=="truc"){System.out.println("bon");}
					value = resultat.getObject(1).toString();
					System.out.print("\t" + resultat.getObject(1).toString() + "\t ");
				}
				System.out.println(value);
				//System.out.println("\n---------------------------------");
				
			//conn.exec("INSERT INTO user values ('2','insert', 'insert','insert','insert','insert','insert','insert','insert','2','2')");

			}

			resultat.close();

			
		} catch (Exception e) {
			e.printStackTrace();
		}			

	}

}

